﻿using System.Linq;

namespace Format_Sample {
    class Program {
        static void Main(string[] args) {
            //string content = "123412341234123412341234123412341234";
            //string separator = " ";
            //int size = 4;
            //string result = stringFormater(content, separator, size);

            //string content = "C:\\NFe\\xml_Nota\\qualquer";
            //string oldValue = "xml_Nota";
            //string newValue = "xml_Nota_Contingencia";

            //string result = stringSubstituter(content, oldValue, newValue);
        }

        /// <summary>
        /// string content = "C:\\NFe\\xml_Nota\\qualquer";
        /// string oldValue = "xml_Nota";
        /// string newValue = "xml_Nota_Contingencia";
        /// string result = stringSubstituter(content, oldValue, newValue);
        /// (result contem o valor: "C:\\NFe\\xml_Nota_Contingencia\\qualquer""
        /// </summary>
        private static string stringSubstituter(string content, string oldValue, string newValue) {            
            int index = content.IndexOf(oldValue);
            content = content.Remove(index, oldValue.Count());
            content = content.Insert(index, newValue);

            return content;
        }

        /// <summary>
        /// Separa os caracteres de acordo com um padrão.
        /// ex:
        ///  string content = "123412341234123412341234123412341234";
        ///  string separator = " ";
        ///  int size = 4;
        ///  string result = stringFormater(content, separator, size);
        ///  (o valor de result é  1234 1234 1234 1234 1234 1234 1234 1234 1234)
        /// </summary>
        private static string stringFormater(string content, string separator, int size) {
            string c = "";
            for (int i = 0; i < content.Length; i += size) {
                c += content.Substring(i, size) + separator;
            }
            return c;
        }
    }
}

